package com.ssy.lingxi.logistics.controller.feign;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.logistics.api.dto.request.OrderFreightRequest;
import com.ssy.lingxi.logistics.api.dto.request.OrderSeparateFreightListRequest;
import com.ssy.lingxi.logistics.api.dto.request.TransferOrderFreightRequest;
import com.ssy.lingxi.logistics.api.dto.response.FreightResponse;
import com.ssy.lingxi.logistics.api.dto.response.OrderSeparateFreightListResponse;
import com.ssy.lingxi.logistics.service.IFreightTemplateService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;

/**
 * @menu 内部服务 - 运费模板
 * @author yzc
 * @version 2.0.0
 * @date 2020/7/10
 */
@RestController
@RequestMapping("/logistics/freightRemote")
public class FreightRemoteFeignController extends BaseController {

    @Resource
    private IFreightTemplateService freightTemplateService;


    /**
     * 运费计算
     * @param request 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/calFreightPrice")
    public Wrapper<BigDecimal> calFreightPrice(@RequestBody @Validated OrderFreightRequest request) {
        return freightTemplateService.calFreightPrice(request);
    }

    /**
     * 订单转单功能 - 新增收货地址及运费计算
     * @param requestList 接口参数
     * @return 返回结果
     */
    @PostMapping(value = "/calFreightPrice/batch")
    public Wrapper<List<FreightResponse>> batchCalFreightPrice(@RequestBody @Validated List<TransferOrderFreightRequest> requestList) {
        return freightTemplateService.batchCalFreightPrice(requestList);
    }

    /**
     * 内部接口 - 批量查询运费（拆单）
     * @param requests 拆单后的商品信息列表
     * @return 查询结果
     */
    @PostMapping(value = "/calFreightPrice/separateOrder")
    public Wrapper<List<OrderSeparateFreightListResponse>> findSeparateOrderFreight(@RequestBody @Valid List<OrderSeparateFreightListRequest> requests) {
        return freightTemplateService.findSeparateOrderFreight(requests);
    }
}
